import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  showSettings: showSettings,
  // 头部导航栏固定
  fixedHeader: fixedHeader,
  // 侧边栏是否有logo
  sidebarLogo: sidebarLogo
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    /**
     * 对象.hasOwnProperty(属性名) =>函数参数：属性名应为字符串
     * 查找对象的属性中是否有传入属性名的属性，有则返回true，没有返回false
     * 说明：不会查找其原型链上的属性或方法
     */
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      // 修改state的key属性值为value
      state[key] = value
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

